Skip to content

Computing crate_hash from metadata encoding instead of HIR (implements #94878) (very draft)#154724

Draft
Daniel-B-Smith wants to merge 1 commit intorust-lang:mainfrom
Daniel-B-Smith:smithdb3/fix-94878
Draft

Computing crate_hash from metadata encoding instead of HIR (implements #94878) (very draft)#154724
Daniel-B-Smith wants to merge 1 commit intorust-lang:mainfrom
Daniel-B-Smith:smithdb3/fix-94878

Conversation

@Daniel-B-Smith
Copy link
Copy Markdown
Contributor

@Daniel-B-Smith Daniel-B-Smith commented Apr 2, 2026

View all comments

This PR converts the crate_hash/SVH to depend on metadata instead of HIR whenever metadata is needed. A trimmed down crate_hash is kept for dylib/binary cases where metadata is not present.

The change to the HIR hash is potentially safe orthogonal this change. Without that change, this PR is a performance regression. I am bundling them because I believe the HIR hash change is more likely to be safe in light of the HIR hash being less load bearing on the SVH.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 2, 2026
@rust-log-analyzer

This comment has been minimized.

@Daniel-B-Smith Daniel-B-Smith force-pushed the smithdb3/fix-94878 branch 5 times, most recently from 24c04d5 to c826667 Compare April 7, 2026 15:59
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Daniel-B-Smith Daniel-B-Smith force-pushed the smithdb3/fix-94878 branch 2 times, most recently from 43a7704 to 338aba3 Compare April 8, 2026 19:34
@rust-log-analyzer

This comment has been minimized.

@Daniel-B-Smith Daniel-B-Smith force-pushed the smithdb3/fix-94878 branch 2 times, most recently from 0ddcd96 to d27cca5 Compare April 8, 2026 21:34
@rust-log-analyzer

This comment has been minimized.

@Daniel-B-Smith Daniel-B-Smith force-pushed the smithdb3/fix-94878 branch 3 times, most recently from 1e5f269 to 4171895 Compare April 9, 2026 14:56
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@Daniel-B-Smith Daniel-B-Smith changed the title #94878 Computing crate_hash from metadata encoding instead of HIR (implements #94878) (very draft) Apr 9, 2026
@nnethercote
Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 9, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 5, 2026
Computing crate_hash from metadata encoding instead of HIR (implements #94878) (very draft)
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 5, 2026

☀️ Try build successful (CI)
Build commit: 9180a5c (9180a5c6a9ad54fd478c2f21273a551c73f21cc9, parent: 740679e1f5554a3c1695317e084809e3fceb9825)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9180a5c): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.4% [0.2%, 0.5%] 6
Regressions ❌
(secondary)
0.5% [0.1%, 1.0%] 12
Improvements ✅
(primary)
-0.5% [-5.5%, -0.1%] 68
Improvements ✅
(secondary)
-1.4% [-5.0%, -0.1%] 46
All ❌✅ (primary) -0.5% [-5.5%, 0.5%] 74

Max RSS (memory usage)

Results (primary -2.9%, secondary -1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.6%, 1.1%] 4
Improvements ✅
(primary)
-2.9% [-4.3%, -2.2%] 3
Improvements ✅
(secondary)
-1.9% [-8.2%, -0.5%] 11
All ❌✅ (primary) -2.9% [-4.3%, -2.2%] 3

Cycles

Results (primary -4.8%, secondary 1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
10.4% [1.1%, 24.8%] 6
Improvements ✅
(primary)
-4.8% [-8.7%, -2.5%] 3
Improvements ✅
(secondary)
-2.7% [-5.8%, -0.4%] 15
All ❌✅ (primary) -4.8% [-8.7%, -2.5%] 3

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 495.494s -> 494.288s (-0.24%)
Artifact size: 394.42 MiB -> 394.47 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 5, 2026
@rust-log-analyzer

This comment has been minimized.

@Daniel-B-Smith Daniel-B-Smith force-pushed the smithdb3/fix-94878 branch 2 times, most recently from 80061c8 to ac45cf7 Compare May 6, 2026 20:18
@Daniel-B-Smith
Copy link
Copy Markdown
Contributor Author

One last perf run as the numbers are already getting into the ballpark.

This run removes the DepPathHash from the HIR hash since https://github.com/rust-lang/rust/blob/4a13f36/compiler/rustc_hir/src/hir.rs#L1583 indicates that the OwnerInfo hashes already contain all of the HIR body in their hashes. opt_hir_hash is no longer used for the SVH, so it only needs to detect changes in the HIR.

I'm relatively confident at this point that there are no more (easy) ways to make any of the three hashes (HIR hash, metadata crate hash, and !metatdata crate hash) meaningfully cheaper. The next two steps are to clean up the various shortcuts I took to get this to the profiling stage faster and start a deeper test by incrementally compiling through a few larger crates/binaries including rustc.

@mejrs
Copy link
Copy Markdown
Contributor

mejrs commented May 6, 2026

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 6, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 6, 2026
Computing crate_hash from metadata encoding instead of HIR (implements #94878) (very draft)
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 6, 2026

☀️ Try build successful (CI)
Build commit: d83f021 (d83f0213d3b2172cfc04784f39a42736048ff7fd, parent: 365c0e1d7a614ca94cb48431dcd2bc6d3b645db1)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (d83f021): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.6%] 7
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 6
Improvements ✅
(primary)
-0.5% [-5.5%, -0.1%] 82
Improvements ✅
(secondary)
-1.4% [-5.1%, -0.1%] 47
All ❌✅ (primary) -0.4% [-5.5%, 0.6%] 89

Max RSS (memory usage)

Results (primary -0.5%, secondary 0.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.8% [1.7%, 1.8%] 2
Regressions ❌
(secondary)
0.9% [0.4%, 2.1%] 6
Improvements ✅
(primary)
-2.0% [-3.6%, -0.7%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.5% [-3.6%, 1.8%] 5

Cycles

Results (primary -4.1%, secondary -2.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.8% [0.5%, 1.1%] 3
Improvements ✅
(primary)
-4.1% [-7.8%, -2.1%] 3
Improvements ✅
(secondary)
-3.3% [-5.3%, -0.7%] 17
All ❌✅ (primary) -4.1% [-7.8%, -2.1%] 3

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 501.88s -> 497.481s (-0.88%)
Artifact size: 395.21 MiB -> 395.12 MiB (-0.02%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels May 7, 2026
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels May 7, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-run-make Area: port run-make Makefiles to rmake.rs A-tidy Area: The tidy tool S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants